home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / glob.test < prev    next >
Text File  |  1993-06-17  |  6KB  |  151 lines

  1. # Commands covered:  glob
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/glob.test,v 1.22 93/06/17 15:41:46 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. # First, create some subdirectories to use for testing.
  32.  
  33. exec rm -rf globTest
  34. exec mkdir globTest globTest/a1 globTest/a2 globTest/a3
  35. exec mkdir globTest/a1/b1 globTest/a1/b2 globTest/a2/b3
  36. exec cat << abc > globTest/x1.c
  37. exec cat << abc > globTest/y1.c
  38. exec cat << abc > globTest/z1.c
  39. exec cat << abc > "globTest/weird name.c"
  40. exec cat << abc > globTest/.1
  41. exec cat << abc > globTest/a1/b1/x2.c
  42. exec cat << abc > globTest/a1/b2/y2.c
  43.  
  44. test glob-1.1 {simple globbing} {
  45.     lsort [glob globTest/x1.c globTest/y1.c globTest/foo]
  46. } {globTest/x1.c globTest/y1.c}
  47. test glob-1.2 {simple globbing} {
  48.     glob {}
  49. } .
  50.  
  51. test glob-2.1 {globbing with braces} {
  52.     glob -nocomplain "{a1,a2}"
  53. } {}
  54. test glob-2.2 {globbing with braces} {
  55.     lsort [glob globTest/{a,b,x,y}1.c]
  56. } {globTest/x1.c globTest/y1.c}
  57. test glob-2.3 {globbing with braces} {
  58.     lsort [glob {globTest/{x1,y2,weird name}.c}]
  59. } {{globTest/weird name.c} globTest/x1.c}
  60.  
  61. test glob-3.1 {asterisks, question marks, and brackets} {
  62.     lsort [glob g*/*.c]
  63. } {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}
  64. test glob-3.2 {asterisks, question marks, and brackets} {
  65.     lsort [glob globTest/?1.c]
  66. } {globTest/x1.c globTest/y1.c globTest/z1.c}
  67. test glob-3.3 {asterisks, question marks, and brackets} {
  68.     lsort [glob */*/*/*.c]
  69. } {globTest/a1/b1/x2.c globTest/a1/b2/y2.c}
  70. test glob-3.4 {asterisks, question marks, and brackets} {
  71.     lsort [glob globTest/*]
  72. } {globTest/a1 globTest/a2 globTest/a3 {globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}
  73. test glob-3.5 {asterisks, question marks, and brackets} {
  74.     lsort [glob globTest/.*]
  75. } {globTest/. globTest/.. globTest/.1}
  76. test glob-3.6 {asterisks, question marks, and brackets} {
  77.     lsort [glob globTest/*/*]
  78. } {globTest/a1/b1 globTest/a1/b2 globTest/a2/b3}
  79. test glob-3.7 {asterisks, question marks, and brackets} {
  80.     lsort [glob {globTest/[xyab]1.*}]
  81. } {globTest/x1.c globTest/y1.c}
  82. test glob-3.8 {asterisks, question marks, and brackets} {
  83.     lsort [glob globTest/*/]
  84. } {globTest/a1/ globTest/a2/ globTest/a3/}
  85.  
  86. # The tests immediately below can only be run at Berkeley, where
  87. # the file-system structure is well-known.
  88.  
  89. if $atBerkeley {
  90.     test glob-4.1 {tildes} {glob ~/.csh*} "/users/ouster/.cshrc"
  91.     test glob-4.2 {tildes} {glob ~ouster/.csh*} "/users/ouster/.cshrc"
  92.  
  93. test glob-5.1 {error conditions} {
  94.     list [catch {glob} msg] $msg
  95. } {1 {wrong # args: should be "glob ?switches? name ?name ...?"}}
  96. test glob-5.2 {error conditions} {
  97.     list [catch {glob globTest/\{} msg] $msg
  98. } {1 {unmatched open-brace in file name}}
  99. test glob-5.3 {error conditions} {
  100.     list [catch {glob globTest/*/gorp} msg] $msg
  101. } {1 {no files matched glob pattern "globTest/*/gorp"}}
  102. test glob-5.4 {error conditions} {
  103.     list [catch {glob goo/* x*z foo?q} msg] $msg
  104. } {1 {no files matched glob patterns "goo/* x*z foo?q"}}
  105. test glob-5.5 {error conditions} {
  106.     list [catch {lsort [glob globTest/*.c goo/*]} msg] $msg
  107. } {0 {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}}
  108. test glob-5.6 {error conditions} {
  109.     list [catch {glob ~no-one} msg] $msg
  110. } {1 {user "no-one" doesn't exist}}
  111. test glob-5.7 {error conditions} {
  112.     set home $env(HOME)
  113.     unset env(HOME)
  114.     set x [list [catch {glob ~/*} msg] $msg]
  115.     set env(HOME) $home
  116.     set x
  117. } {1 {couldn't find HOME environment variable to expand "~/*"}}
  118. test glob-5.8 {error conditions} {
  119.     list [catch {glob globTest/{a1,a2}/\{} msg] $msg
  120. } {1 {unmatched open-brace in file name}}
  121. test glob-5.9 {error conditions} {
  122.     list [catch {glob globTest/*/\{} msg] $msg
  123. } {1 {unmatched open-brace in file name}}
  124.  
  125. exec chmod 000 globTest
  126. if {$user != "root"} {
  127.     test glob-6.1 {setting errorCode variable} {
  128.     string tolower [list [catch {glob globTest/*} msg]  $msg $errorCode]
  129.     } {1 {couldn't read directory "globtest": permission denied} {posix eacces {permission denied}}}
  130. }
  131. exec chmod 755 globTest
  132.  
  133. test glob-7.1 {-nocomplain switch} {
  134.     list [catch {glob -nocomplai} msg] $msg
  135. } {1 {bad switch "-nocomplai": must be -nocomplain or --}}
  136. test glob-7.2 {-nocomplain switch} {
  137.     list [catch {glob -nocomplain} msg] $msg
  138. } {1 {wrong # args: should be "glob ?switches? name ?name ...?"}}
  139. test glob-7.3 {-nocomplain switch} {
  140.     list [catch {glob -nocomplain goo/*} msg] $msg
  141. } {0 {}}
  142. test glob-7.4 {-- switch} {
  143.     list [catch {glob -- -nocomplain} msg] $msg
  144. } {1 {no files matched glob patterns "-nocomplain"}}
  145. test glob-7.5 {bogus switch} {
  146.     list [catch {glob -gorp} msg] $msg
  147. } {1 {bad switch "-gorp": must be -nocomplain or --}}
  148.  
  149. exec rm -rf globTest
  150.